/*
PearReview - The peer review assistant.
Copyright (C) 2009  Dimitrij Pankratz, Anton Musichin
http://www.pearreview.com, info@pearreview.com

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/
package com.pearreview.ui;

import java.awt.Color;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;

import javax.swing.JLabel;
import javax.swing.plaf.basic.BasicLabelUI;

/**
 * For painting a label text with shadow. In this case the shadow is for 
 * simulating an engraved font type. The dark color font is in front of
 * light color font moved by one point down.
 * 
 * To show the user a focused label, the text can be underlined.
 *
 */
public class ShadowLabelUI extends BasicLabelUI {
	
	private Color shadowColor = new Color(0xededed);
	private boolean focused = false;
	
	@Override
    protected void paintEnabledText(JLabel l, Graphics g, String s,
           int textX, int textY) {
    	
    	Graphics2D g2 = (Graphics2D) g;
    	g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 
				RenderingHints.VALUE_ANTIALIAS_ON);
    	FontMetrics fm = g2.getFontMetrics();
    	
    	//draw shadow
        g2.setColor(shadowColor);
        g2.drawString(l.getText(), textX, textY+1);

        //underline the shadow
        if (focused) {
        	g2.drawLine(textX, 
            		textY+3, 
            		(int)(textX+fm.getStringBounds(s, g2).getWidth()), 
            		textY+3);
        }
        
        //draw normal text
        g2.setColor(l.getForeground());
        g2.drawString(l.getText(), textX, textY);
        
        //underline normal text
        if (focused) {
	        g2.drawLine(textX, 
	        		textY+2, 
	        		(int)(textX+fm.getStringBounds(s, g2).getWidth()), 
	        		textY+2);
        }
    }
    
    public void setShadowColor(Color c) {
    	shadowColor = c;
    }
    
    public void setFocused(boolean f) {
    	focused = f;
    }
    
    public boolean getFocused() {
    	return focused;
    }
}